//
//  SLRTheNavigationView.m
//  shunlianPower2
//
//  Created by xiaoruo on 2018/7/21.
//  Copyright © 2018年 顺联网络. All rights reserved.
//

#import "SLRTheNavigationView.h"


@interface SLRTheNavigationView ()


@end


@implementation SLRTheNavigationView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
//        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop);

        [self addUI];
    }
    return self;
}

-(void)addUI{
    
    _bgImageView = [UIImageView new];
    
    _leftButton = [[QMUIButton alloc] init];
    [_leftButton addTarget:self action:@selector(theLeftAndRightButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    _rightButton = [[QMUIButton alloc] init];
    _rightButton.spacingBetweenImageAndTitle = 4;
    [_rightButton addTarget:self action:@selector(theLeftAndRightButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    _titleLabel = [UILabel new];
    _titleLabel.font = UIFontMake(17);
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    
    _navigationGreyLine = [UIView new];
    _navigationGreyLine.backgroundColor = UIColorHex(#eeeeee);
    _navigationGreyLine.hidden = YES;
    
    
    [self addSubview:_bgImageView];
    
    [self addSubview:_leftButton];
    [self addSubview:_rightButton];
    [self addSubview:_titleLabel];
    [self addSubview:_navigationGreyLine];

    
    CGFloat ww = 35, top = StatusBarHeight;
    _bgImageView.frame = self.bounds;
    _leftButton.frame = CGRectMake(0, top, ww, NavigationBarHeight);
    _rightButton.frame = CGRectMake(self.width -10-ww, top, ww, NavigationBarHeight);
    _titleLabel.frame = CGRectMake(55, top, self.width -55*2, NavigationBarHeight);
    _navigationGreyLine.frame = CGRectMake(0, self.bottom-0.5, self.width, 0.5);
    
}

-(void)theLeftAndRightButtonClick:(QMUIButton *)button{
    
    if (button == _leftButton) {
        if (self.SLRTheNavigationViewLeftButtonClickBlock) {
            self.SLRTheNavigationViewLeftButtonClickBlock();
        }
    }
    if (button == _rightButton) {
        if (self.SLRTheNavigationViewRightButtonClickBlock) {
            self.SLRTheNavigationViewRightButtonClickBlock();
        }
    }
    
}



-(void)setBgColor:(UIColor *)bgColor{
    _bgImageView.backgroundColor = bgColor;
}
-(void)setBgImage:(UIImage *)bgImage{
    _bgImageView.image = bgImage;
}
-(void)setTheTitleString:(NSString *)theTitleString{
    _titleLabel.text = theTitleString;
}
-(void)setTheTitleAttributedString:(NSAttributedString *)theTitleAttributedString{
    _titleLabel.attributedText = theTitleAttributedString;
}
-(void)setTheTitleColor:(UIColor *)theTitleColor{
    _titleLabel.textColor = theTitleColor;
}
-(void)setLeftButtonImage:(UIImage *)leftButtonImage{
    [_leftButton setImage:leftButtonImage forState:UIControlStateNormal];
}
-(void)setRightButtonImage:(UIImage *)rightButtonImage{
    [_rightButton setImage:rightButtonImage forState:UIControlStateNormal];
}
-(void)setRightButtonTitleString:(NSString *)rightButtonTitleString{
    
    [_rightButton setTitle:rightButtonTitleString forState:UIControlStateNormal];
    _rightButton.titleLabel.font = UIFontMake(15);
    
    CGFloat buttonWWW = rightButtonTitleString.length *15 + 10,
    ww = 35, top = (NavigationBarHeight-ww)/2.0 +StatusBarHeight;
    _rightButton.frame = CGRectMake(self.width -10-buttonWWW, top, buttonWWW, ww);
}
-(void)setRightButtonTitleColor:(UIColor *)rightButtonTitleColor{
    [_rightButton setTitleColor:rightButtonTitleColor forState:UIControlStateNormal];
}



-(void)setRightButtonImagesArray:(NSArray *)rightButtonImagesArray{
    
 
    
}

-(void)setIsHaveNavigationGreyLine:(BOOL)isHaveNavigationGreyLine{
    _navigationGreyLine.hidden = isHaveNavigationGreyLine==YES ? NO : YES;
}


@end
